package view.common;

import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.awt.*;

public class MultiLineCellRenderer extends JTextArea implements TableCellRenderer {
    public MultiLineCellRenderer() {
        setLineWrap(true);
        setWrapStyleWord(true);
        setOpaque(true);
        setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        setFont(new Font("微软雅黑", Font.PLAIN, 12));
    }
    
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        setText(value != null ? value.toString() : "");
        
        // 设置背景和前景色
        if (isSelected) {
            setBackground(table.getSelectionBackground());
            setForeground(table.getSelectionForeground());
        } else {
            setBackground(table.getBackground());
            setForeground(table.getForeground());
            
            // 为第一列（节次列）设置特殊背景色
            if (column == 0) {
                setBackground(new Color(240, 240, 240));
            }
        }
        
        // 设置首选大小以适应内容
        setSize(table.getColumnModel().getColumn(column).getWidth(),
                getPreferredSize().height);
        
        return this;
    }
} 